import request from '@/utils/request'
// import qs from 'qs'

// 获取自身防护模块信息
export function getAccessInfo (params) {
  var data = fromData(params)
  return request({
    url: '/local_access/getAccessInfo',
    method: 'post',
    data
  })
}

// 设置是否允许管理口进行业务面处理
export function changeManagementPort (params) {
  var data = fromData(params)
  return request({
    url: '/local_access/changeManagementPort',
    method: 'post',
    data
  })
}

// 设置是否开启自身扫描防护
export function changeAccessScan (params) {
  var data = fromData(params)
  return request({
    url: '/local_access/changeAccessScan',
    method: 'post',
    data
  })
}

// 限制管理源地址
export function limitSrcAddr (params) {
  var data = fromData(params)
  return request({
    url: '/local_access/limitSrcAddr',
    method: 'post',
    data
  })
}

// 设置管理口允许的访问方式
export function changeManagementPortInfo (params, time = 600 * 1000) {
  var data = fromData(params)
  return request({
    url: '/local_access/changeManagementPortInfo',
    method: 'post',
    timeout: time,
    data
  })
}

// 设置业务口是否可以管理
export function changeServicePort (params) {
  var data = fromData(params)
  return request({
    url: '/local_access/changeServicePort',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
